package ooday04;

public class Test {
    public static void main(String[] args) {
        Animal[] animals = new Animal[6];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 2, "白");
        animals[2] = new Dog("小灰", 2, "灰");
        animals[3] = new Fish("小金", 2, "金");
        animals[4] = new Fish("小黄", 2, "黄");
        animals[5] = new Chick("大花", 1, "花");
        for (int i=0;i<animals.length;i++) {
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Chick){
                Chick chick = (Chick)animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Dog){
                Dog dog= (Dog) animals[i];
                dog.lookHome();
            }
            if (animals[i] instanceof Fish){
                Fish s= (Fish) animals[i];
                s.swim();
            }
        }






        Master master = new Master();
        Dog dog = new Dog("小黑",2,"黑");
        Fish fish = new Fish("小金",1,"金");
        Chick chick = new Chick("小花",3,"花");
        master.feed(dog); //在传参的同时，系统自动做了向上造型
        master.feed(fish);
        master.feed(chick);

















        /*
        Animal[] animals = new Animal[6];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 2, "白");
        animals[2] = new Dog("小灰", 2, "灰");
        animals[3] = new Fish("小金", 2, "金");
        animals[4] = new Fish("小黄", 2, "黄");
        animals[5] = new Chick("大花", 1, "花");
        for (int i=0;i<animals.length;i++){
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();
            Master master = new Master();
            Dog dog= new Dog("小黑", 2, "黑");
      }
         */























        /*
        Dog dog = new Dog("小黑", 2, "黑");
        System.out.println(dog.name);
        dog = null;//表示空
        System.out.println(dog.name);
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");
        dogs[1] = new Dog("小白", 2, "白");
        dogs[2] = new Dog("小灰", 2, "灰");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i = 0; i < dogs.length; i++) {
            System.out.println(dogs[i].name);
            dogs[i].eat();

        }
        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("大花", 1, "花");
        chicks[1] = new Chick("小花", 3, "白");
        for (int i = 0; i < chicks.length; i++) {
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }
        Fish[] fish = new Fish[4];
        fish[0] = new Fish("小金", 2, "金");
        fish[1] = new Fish("小黄", 2, "黄");
        fish[2] = new Fish("小黑", 2, "黑");
        fish[3] = new Fish("小红", 2, "红");
        for (int i = 0; i < fish.length; i++) {
            System.out.println(fish[i].name);
            fish[i].eat();
        }



         */























        /*
        Dog dog = new Dog("小黑", 2, "黑");
        System.out.println(dog.name);
        dog = null;//表示空
        System.out.println(dog.name);
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑", 2, "黑");
        dogs[1] = new Dog("小黑", 2, "黑");
        dogs[2] = new Dog("小黑", 2, "黑");
        System.out.println(dogs[0].name);
        dogs[1].age = 4;
        dogs[2].swim();
        for (int i = 0; i < dogs.length; i++) {
            System.out.println(dogs[i].name);
            dogs[i].eat();

        }
        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("大花", 1, "花");
        chicks[1] = new Chick("小花", 3, "白");
        for (int i = 0; i < chicks.length; i++) {
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }
            Fish[] fish = new Fish[4];
            fish[0] = new Fish("小金", 2, "金");
            fish[1] = new Fish("小黄", 2, "黄");
            fish[2] = new Fish("小黑", 2, "黑");
            fish[3] = new Fish("小红", 2, "红");
            for (int i = 0; i < fish.length; i++) {
                System.out.println(fish[i].name);
                fish[i].eat();


        }

         */

    }}
